package com.yonyougov.devops.cruxcisupport.roleapp;

import com.yonyougov.devops.cruxcisupport.roleapp.vo.GetAppIdsByRoleIdsReqVo;
import com.yonyougov.devops.cruxcisupport.roleapp.vo.RoleAppPageByRoleIdDto;
import com.yonyougov.devops.cruxcisupport.roleapp.vo.RoleAppVo;
import com.yonyougov.devops.fwc.core.dao.impl.BaseDaoImpl;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

/**
 * t_role_app数据层实现
 */
@Repository
public class RoleAppDaoImpl extends BaseDaoImpl<RoleAppEntity, BigInteger> implements RoleAppDao {
    //<!--用户自定义代码开始-->
    private final SqlSessionTemplate sqlSessionTemplate;

    public RoleAppDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    /**
     * 查询角色和应用的关联关系
     * 条件: 角色id, 应用名称
     *
     * @param roleAppPageByRoleIdDto [com.yonyougov.devops.cruxcisupport.roleapp.vo.RoleAppPageByRoleIdDto]
     * @return [java.util.List]
     */
    @Override
    public int countRoleAppByRoleId(RoleAppPageByRoleIdDto roleAppPageByRoleIdDto) {
        String statement = RoleAppEntity.class.getName() + "Mapper.countByLikeRoleApp";
        return sqlSessionTemplate.selectOne(statement, roleAppPageByRoleIdDto);
    }

    /**
     * 查询角色和应用的关联关系
     * 条件: 角色id, 应用名称
     *
     * @param roleAppPageByRoleIdDto [com.yonyougov.devops.cruxcisupport.roleapp.vo.RoleAppPageByRoleIdDto]
     * @return [java.util.List]
     */
    @Override
    public List<RoleAppVo> findRoleAppPageByRoleId(RoleAppPageByRoleIdDto roleAppPageByRoleIdDto) {
        String statement = RoleAppEntity.class.getName() + "Mapper.findAllLikeByRoleApp";
        return sqlSessionTemplate.selectList(statement, roleAppPageByRoleIdDto);
    }

    @Override
    public void addBatch(List<RoleAppEntity> params) {
        String statement = RoleAppEntity.class.getName() + "Mapper.addBatch";
        sqlSessionTemplate.insert(statement, params);
    }

    @Override
    public void deleteBatchRoleAppByIds(List<BigInteger> ids) {
        String statement = RoleAppEntity.class.getName() + "Mapper.deleteBatchRoleAppByIds";
        sqlSessionTemplate.insert(statement, ids);
    }

    @Override
    public List<BigInteger> getAppIdsByRoleIds(GetAppIdsByRoleIdsReqVo params) {
        String statement = RoleAppEntity.class.getName() + "Mapper.getAppIdsByRoleIds";
        return sqlSessionTemplate.selectList(statement, params);
    }

    @Override
    public List<BigInteger> getCurrentUserAppIds(List<BigInteger> roleIds) {
        String statement = RoleAppEntity.class.getName() + "Mapper.getCurrentUserAppIds";
        return sqlSessionTemplate.selectList(statement, roleIds);
    }

    //<!--用户自定义代码结束-->
}
